package threading;
class MyRunnable implements Runnable{
    @Override
    public void run() {
        while(true){
            System.out.println("hello t");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
public class ThreadDemo2 {

    public static void main(String[] args) {
        MyRunnable runnable = new MyRunnable();//这里创建一个实现Runnable接口的类的对象
        //这里直接创建Thread类的对象，不用实现Thread的子类。
        Thread t = new Thread(runnable);//将这个对象作为Thread类的构造方法的参数
        t.start();
        while(true){
            System.out.println("hello main");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
